<include file="Public:header" />
<div class="container">
	<!-- Docs nav ================================================== -->
	<div style="margin-top:10px; font-size:14px;">
		<ul class="nav nav-tabs">
		  <li class="active">
			<a href="{:U('task/index')}"><img src="__PUBLIC__/img/renwu.png"/>&nbsp; {:L('TASK')}</a>
		  </li>
		  <li><a href="{:U('task/analytics')}"><img src="__PUBLIC__/img/tongji.png"/> &nbsp;{:L('STATISTICS')}</a></li>
		  <!-- <li><a href="http://5kcrm.com/index.php?m=doc&a=index&id=14" target="_blank" style="font-size: 12px;color: rgb(255, 102, 0);"><img width="20px;" src="__PUBLIC__/img/help.png"/> {:L('HELP')}</a></li> -->
		</ul>
	</div>
	<include file="Public:alert" />
	<p class="view"><b>{:L('VIEW_NAV')}</b>
	<img src=" __PUBLIC__/img/by_owner.png"/> <a href="{:U('task/index')}" <if condition="$Think.get.by eq null">class="active"</if>>{:L('ALL')}</a> |
	<a href="{:U('task/index','by=me')}" <if condition="$Think.get.by eq 'me'">class="active"</if>>{:L('MY_TASK')}</a> | 
	<a href="{:U('task/index','by=create')}" <if condition="$Think.get.by eq 'create'">class="active"</if>>{:L('I_ASSIGNED_TASKS')}</a>  &nbsp;  &nbsp; 
	<img src=" __PUBLIC__/img/by_status.png"/> <a href="{:U('task/index','by=s1')}" <if condition="$Think.get.by eq 's1'">class="active"</if>>{:L('NOT_START')}</a> | 	
	<a href="{:U('task/index','by=s2')}" <if condition="$Think.get.by eq 's2'">class="active"</if>>{:L('DELAY')}</a> | 	
	<a href="{:U('task/index','by=s3')}" <if condition="$Think.get.by eq 's3'">class="active"</if>>{:L('ONGOING')}</a> | 	
	<a href="{:U('task/index','by=s4')}" <if condition="$Think.get.by eq 's4'">class="active"</if>>{:L('COMPLETED')}</a> | 	
	<a href="{:U('task/index','by=closed')}" <if condition="$Think.get.by eq 'closed'">class="active"</if>>{:L('CLOSED')}</a>  &nbsp;  &nbsp; 
	<img src="__PUBLIC__/img/by_time.png"/> <a href="{:U('task/index','by=today')}" <if condition="$Think.get.by eq 'today'">class="active"</if>>{:L('TODAY_DEADLINE')}</a> | 
	<a href="{:U('task/index','by=week')}" <if condition="$Think.get.by eq 'week'">class="active"</if>>{:L('THIS_WEEK_DEADLINE')}</a> | 
	<a href="{:U('task/index','by=month')}" <if condition="$Think.get.by eq 'month'">class="active"</if>>{:L('THIS_MONTH_DEADLINE')}</a> |
	<a href="{:U('task/index','by=add')}" <if condition="$Think.get.by eq 'add'">class="active"</if>>{:L('RECENTLY_ASSIGN')}</a> | 
	<a href="{:U('task/index','by=update')}" <if condition="$Think.get.by eq 'update'">class="active"</if>>{:L('RECENTLY_UPDATE')}</a> &nbsp;  &nbsp; 
	<a href="{:U('task/index','by=deleted')}" <if condition="$Think.get.by eq 'deleted'">class="active"</if>><img src="__PUBLIC__/img/task_garbage.png"/> {:L('RECYCLE_BIN')}</a> &nbsp;  &nbsp; 
	</p>
	<div class="row"> 
		
		<div class="span12" style="height:36px;">
			<ul class="nav pull-left">
				<li class="pull-left"><if condition="session('?admin') or $Think.get.by neq 'deleted'"><a id="delete"  class="btn"><i class="icon-remove"></i>&nbsp;{:L('DELETE')}</a></if>&nbsp; </li>
				<li class="pull-left">
				<form class="form-inline" id="searchForm" action="" method="get">
					<ul class="nav pull-left">
					<li class="pull-left">&nbsp; 
						<select id="field" style="width:auto" onchange="changeCondition()" name="field">
							<option class="all" value="all">{:L('ANY_FIELDS')}</option>
							<option class="word" value="subject">{:L('TASK_SUBJECT')}</option>
							<option class="role" value="owner_role_id">{:L('EXECUTOR')}</option>
							<option class="role" value="creator_role_id">{:L('CREATOR_ROLE')}</option>
							<option class="task_status" value="status">{:L('TASK_STATUS')}</option>
							<option class="task_priority" value="priority">{:L('PRECEDENCE')}</option>
							<option class="word" value="description">{:L('DESCRIPTION')}</option>
							<option class="date" value="due_date">{:L('DEADLINE')}</option>
							<option class="date" value="create_date">{:L('CREATE_DATE')}</option>
							<option class="date" value="update_date">{:L('UPDATE_DATE')}</option>
						</select>&nbsp;&nbsp;
					</li>
					<li id="conditionContent" class="pull-left">
						<select id="condition" style="width:auto" name="condition" onchange="changeSearch()">
							<option value="contains">{:L('CONTAINS')}</option>
							<option value="is">{:L('IS')}</option>
							<option value="start_with">{:L('START_WITH')}</option>
							<option value="end_with">{:L('END_WITH')}</option>
							<option value="is_empty">{:L('IS_EMPTY')}</option>
						</select>&nbsp;&nbsp;
					</li>
					<li id="searchContent" class="pull-left">
						<input id="search" type="text" class="input-medium search-query" name="search"/>&nbsp;&nbsp;
					</li>
					<li class="pull-left">
						<input type="hidden" name="m" value="Task"/>
						<input type="hidden" name="act" id="act" value="index"/>
						<input type="hidden" name="daochu" id="daochu" value=""/>
						<input type="hidden" name="current_page" id="current_page" value=""/>
						<input type="hidden" name="export_limit" id="export_limit" value=""/>
						<if condition="$Think.get.by neq null"><input type="hidden" name="by" value="{$Think.get.by}"/></if>
						<input type="submit" id="dosearch" class="btn" value="{:L('SEARCH')}"/>
					</li></ul>
				</form>
				</li>
			</ul>
			<div class="pull-right">
				<a href="{:U('task/add')}" class="btn btn-primary"><i class="icon-plus"></i>&nbsp; {:L('CREATE_TASK')}</a>&nbsp;
				<div class="btn-group">
					<button class="btn btn-primary dropdown-toggle" data-toggle="dropdown"> <i class="icon-wrench"></i>&nbsp; {:L('TASK_TOOLS')}<span class="caret"></span></button>
					<ul class="dropdown-menu">
						<!--<li><a href="javascript:return(0);" id="import_excel"  class="link">导入任务</a></li>-->
						<li><a href="javascript:return(0);" id="excelExport" class="link"><i class="icon-download"></i> {:L('IMPORT_TASK')}</a></li>
					</ul>
				</div>
			</div>
		</div>
		<div class="span12">
			<form id="form1" action="" method="post">
				<table class="table table-hover table-striped table_thead_fixed">
					<empty name="task_list">
						<tr><td>{:L('EMPTY_TPL_DATA')}</td></tr>
					<else />
						<thead>
							<tr>
								<th><input type="checkbox" id="control_all" name="control_all"/></th>
								<th width="20px">&nbsp;</th>
								<th>{:L('THEME')}</th>
								<th>{:L('RELATED_INFO')}</th>
								<th>{:L('EXECUTOR')}</th>	
								<if condition="C('ismobile') neq 1">
								<th>{:L('STATUS')}</th>
								<th>{:L('PRECEDENCE')}</th></if>
								<if condition="C('ismobile') neq 1 and $Think.get.by eq 'deleted'">
									<th>{:L('DELETE_ROLE')}</th>
									<th>{:L('DELETE_TIME')}</th>
								<elseif condition="C('ismobile') neq 1" />
									<th>{:L('CREATOR_ROLE')}</th>
									<th>
										<if condition="$_GET['asc_order'] == 'due_date'">
											<a href="{:U('task/index','desc_order=due_date&'.$parameter)}">
												{:L('END_DATE')}&nbsp;<img src="__PUBLIC__/img/arrow_up.png">
											</a>
										<elseif condition="$_GET['desc_order'] == 'due_date'"/>
											<a href="{:U('task/index','asc_order=due_date&'.$parameter)}">
												{:L('END_DATE')}&nbsp;<img src="__PUBLIC__/img/arrow_down.png">
											</a>
										<elseif condition="$Think.get.by eq 's4'"/>
											完成时间&nbsp;<img src="__PUBLIC__/img/arrow_down.png">
										<else/>
											<a href="{:U('task/index','desc_order=due_date&'.$parameter)}">{:L('END_DATE')}</a>
										</if>
									</th>
								</if>
								<th>{:L('OPERATING')}</th>
							</tr>
						</thead>
						<tfoot>
							<tr><td colspan="10">
								<p>{:L('NOTE')} <img src="__PUBLIC__/img/task_owner.png"/> {:L('MY_RESPONSIBLE')} &nbsp; <img src="__PUBLIC__/img/task_creator.png"/>{:L('I_ASSIGNED')} &nbsp; </p>{$page}<include file="Public:listrows" />
							</td></tr>
						</tfoot>
						<tbody>
							<volist name="task_list" id="vo">
								<tr>
									<td>
										<input name="task_id[]" class="check_list" type="checkbox" value="{$vo.task_id}"/>
									</td>
									<td>	
										<!-- <if condition="session('role_id') eq $vo['owner_role_id'] "><img src="__PUBLIC__/img/task_owner.png"/><elseif condition="session('role_id') eq $vo['creator_role_id'] "/><img src="__PUBLIC__/img/task_creator.png"/></if> -->
										<if condition="session('role_id') eq $vo['creator_role_id']">
											<img src="__PUBLIC__/img/task_creator.png" />
											<else/>
												<volist name="vo['owner']" id="v">
													<notempty name="v.user_name">
														<input type="hidden" rel="{$v.role_id}" />
														<if condition="session('role_id') eq $v['role_id']">
														<img src="__PUBLIC__/img/task_owner.png" />
														</if>
													</notempty>
												</volist>
										</if>
																				
									</td>
									<td><a href="{:U('task/view','id='.$vo['task_id'])}">{$vo.subject}</a></td>
									<td>{$vo.module.module_name} {$vo.module.name}</td>
									<td>
										<volist name="vo['owner']" id="v">
											<notempty name="v.user_name">
												<a class="role_info" rel="{$v.role_id}" href="javascript:void(0)">{$v.user_name},</a>
											</notempty>
										</volist>
									</td>
									<if condition="C('ismobile') neq 1">
									<td>{$vo.status}</td>
									<td>{$vo.priority}</td></if>
									<if condition="C('ismobile') neq 1 and $Think.get.by eq 'deleted'">
										<td><notempty name="vo.deletor.user_name"><a class="role_info" rel="{$vo.deletor.role_id}" href="javascript:void(0)">{$vo.deletor.user_name}</a></notempty></td>
										<td><notempty name="vo.delete_time">{$vo.delete_time|date="Y-m-d H:i",###}</notempty></td>
									<elseif condition="C('ismobile') neq 1" />
										<td><notempty name="vo.creator.user_name"><a class="role_info" rel="{$vo.creator.role_id}" href="javascript:void(0)">{$vo.creator.user_name}</a></notempty></td>
										
										<if condition="$Think.get.by eq 's4'">
											<td>
												<span style="color:green;"><if condition="$vo.finish_date neq 0">{$vo.finish_date|date="Y-m-d H:i",###}</if></span>
											</td>
										<else/>
										
										<td>
										<?php if($vo['due_date'] <= 0){ ?>
										<?php }elseif ($vo['diff_days'] > 0) { ?><img src="__PUBLIC__/img/task_mtime.png"/> {:L('DAYS_LEFT', array($vo['diff_days']))}
										<?php } elseif($vo['diff_days'] < 0) { ?>
										<img width="12px" src="__PUBLIC__/img/task_alert.png"/>&nbsp;&nbsp;<span style="color:red;">{:L('OVERDUE_DAYS', array(abs($vo['diff_days'])))}</span>
										<?php } else{ ?><img src="__PUBLIC__/img/task_ltime.png"/>&nbsp;<span style="color:rgb(255, 0, 224);">{:L('COMPLETED_TODAY')}</span>
										<?php } ?>
										</td>
										</if>
									</if>
									
									
									<td>
										<a href="{:U('task/view','id='.$vo['task_id'])}">{:L('VIEW')}</a>&nbsp;
										<if condition="$Think.get.by neq 'deleted'">
											<a href="{:U('task/edit','id='.$vo['task_id'])}">{:L('EDIT')}</a>&nbsp;
										<else />
											<a href="{:U('task/revert','id='.$vo['task_id'])}" title="{:L('RESET')}">{:L('RESET')}</a>
										</if>
										 <if condition="$vo['isclose'] eq 0 and $Think.get.by neq 'deleted' and ($vo['creator']['role_id'] eq $_SESSION['role_id'] or $Think.session.admin eq 1 )"><a href="{:U('task/close','id='.$vo['task_id'])}">{:L('CLOSE')} &nbsp;</a><elseif condition="$Think.get.by neq 'deleted' and $vo['isclose'] eq 1 and ($vo['creator']['role_id'] eq $_SESSION['role_id'] or $Think.session.admin eq 1 ) "/><a href="{:U('task/open','id='.$vo['task_id'])}">{:L('OPEN')} &nbsp;</a></if> 
									</td>
								</tr>
							</volist>
						</tbody>
					</empty>
				</table>
			</form>
		</div>
	</div>
</div>
<div class="hide" id="dialog-import" title="{:L('IMPORT_DATA')}">loading...</div>
<div class="hide" id="dialog-role-info" title="{:L('DIALOG_USER_INFO')}">loading...</div>
<script type="text/javascript">
var url = "{:U('task/getcurrentstatus')}";
var limit_size = 1;
var count = {$count};
var i = 1;  
function remainTime(){
	var id_array = new Array(); 
	$("input[class='check_list']:checked").each(function() {   
		id_array.push($(this).val());
	});  
	$.get(url,function(data){
		if(data.data == 0){
			if((i-1)*limit_size < count){
				$("#act").val('excel');	
				$("#daochu").val(id_array);
				$("#current_page").val(i);
				$("#export_limit").val(limit_size);
				$("#searchForm").submit();
				setTimeout("remainTime()",1000); 
				i++; 
			}else{
				alert('导出完毕!');
				i = 1;
			}
		}else{
			setTimeout("remainTime()",1000); 
		}
	}, 'json');
}
<if condition="C('ismobile') eq 1">width=$('.container').width() * 0.9;<else/>width=800;</if>
$("#dialog-role-info").dialog({
    autoOpen: false,
    modal: true,
	width: width,
	maxHeight: 400,
	position: ["center",100]
});
$("#dialog-import").dialog({
	autoOpen: false,
	modal: true,
	width: width,
	maxHeight: 400,
	position: ["center",100]
});
function changeContent(){
	a = $("#select1  option:selected").val();
	window.location.href="{:U('task/index','by=')}"+a;
}

$(function(){
<if condition="$Think.get.field neq null">
	$("#field option[value='{$Think.get.field}']").prop("selected", true);changeCondition();
	$("#condition option[value='{$Think.get.condition}']").prop("selected", true);changeSearch();
	$("#search").prop('value', '{$Think.get.search}');
</if>
	$("#control_all").click(function(){
		$("input[class='check_list']").prop('checked', $(this).prop("checked"));
	});
	$('#delete').click(function(){
		if(confirm("{:L('CONFIRM_DELETE')}")){
		<if condition="$Think.session.admin eq 1 and $Think.get.by eq 'deleted'">
			$("#form1").attr('action', '{:U("task/completedelete")}');
			$("#form1").submit();
		<else />
			$("#form1").attr('action', '{:U("task/delete")}');
			$("#form1").submit();
		</if>
		}
	});
	

	$("#excelExport").click(function(){
		if(count > limit_size){
			if(confirm('当前导出量过大，将分几次导出，可能需要您等待一段时间，是否继续?')){
				remainTime();
			}
		}else{
			if(confirm("{:L('CONFIRM_TO_IMPORT')}")){
				remainTime();
			}
		}
		/*if(confirm("{:L('CONFIRM_TO_IMPORT')}")){ 
			$("#act").val('excel');	
			$("#searchForm").submit();
		}*/
	})
	
	$("#dosearch").click(function(){
		result = checkSearchForm();
		if(result) $("#act").val('search');$("#searchForm").submit();
	});
	
	$("#import_excel").click(function(){
		$('#dialog-import').dialog('open');
		$('#dialog-import').load('{:U("task/excelimport")}');
	});
	$(".role_info").click(function(){
		$role_id = $(this).attr('rel');
		$('#dialog-role-info').dialog('open');
		$('#dialog-role-info').load('{:U("user/dialoginfo","id=")}'+$role_id);
	});
});
</script>
<include file="Public:footer" />